/*
 * Dalek.h
 *
 *  Created on: 23/05/2013
 *      Author: roger
 */

#ifndef MENU_H_
#define MENU_H_

#include "AppRegistry.h"

//#define DEBUG_DALEK
#define RADIUS 16
#define DALEK_COUNT 5
#define SENSITIVITY 10

static char small_dalek_bitmap[] PROGMEM =
		"!!!!!!!!!!!!$QQ-``]4``]4``]4!!!!!!!!!!!!BX*S#AI+!!!!!!!!!!!!!!!!"
				"!!!!``]4``]4``]4``]4``]4``]4``]4BX*S&B97!!!!!!!!!!!!!!!!!!!!``]4"
				"$QQ-$QQ-$QQ-``]4!!!!!!!!BX*S!1%\"!!!!!!!!!!!!!!!!!!!!``]4``]4``]4"
				"``]4``]4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``]4$QQ-$QQ-$QQ-``]4"
				"!!!!!!!!!!!!!!!!!1%\"!!!!!!!!!!!!``]4``]4``]4``]4``]4``]4!!!!!!!!"
				"!!!!!!!!!!!!BX*S!!!!!!!!``]4``]4``]4``]4``]4``]4``]4``]4``]4``]4"
				"``]4BX*S!1%\"!!!!``]4$QQ-``]4$QQ-``]4$QQ-``]4!!!!!!!!!!!!!!!!BX*S"
				"\"A9'``]4``]4``]4``]4``]4``]4``]4``]4!!!!!!!!!!!!!!!!!!!!%B)3``]4"
				"$QQ-``]4``]4$QQ-``]4$QQ-``]4``]4!!!!!1%\"!!!!!!!!!!!!``]4``]4``]4"
				"``]4``]4``]4``]4``]4``]4%2%2!!!!!!!!!!!!!!!!``]4$QQ-``]4``]4$QQ-"
				"``]4$QQ-``]4``]4$!Q-!!!!!!!!!!!!``]4``]4$QQ-``]4``]4$QQ-``]4$QQ-"
				"``]4``]4``]4!!!!!!!!!!!!``]4``]4``]4``]4``]4``]4``]4``]4``]4``]4"
				"``]4!!!!!!!!!!!!";

static char dalek_bitmap[] PROGMEM =
			"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-D)S86V>($)]!!!!!!!!!!!!!!!!,S]P"
			"2E:'K;GJS=H*X.T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			"882_BL`9R^HBL^XQFM(5V^85M>@H?-0F````P.TLL.HNRN\\I]?`OQ/$O@M4D]OXL"
			"N><FDMTIJ>\\Y!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$4F..H[>L=40(97T"
			"EL'`X>P;5KD/)(WF````GLX.(YO\\J]<5^P0R4K0)/I[UZO4DO]\\8+)'I<*7I!!!!"
			"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NL+QV>44T-L)Y>@3````````V-\\,W^42"
			"````\\?LJ`@(M````````^?`N^/\\LZ_@HZO@H````6V24!!!!!!!!!!!!!!!!!!!!"
			"!!!!!!!!!!!!6GRW@LX9RM#^M^`TC<P2````LM(*Q/8UB,(&````N^PL>M,E````"
			"````NN8DL^PPO>0?O^4@L^XRI.$E*&JR!!!!!!!!!!!!!!!!!!!!!!!!!!!!E;KW"
			"89/5U-P*0)?ID;KX````G\\@$(I;T@*CE````4K$%.YGN````````LM80%X7AH,H'"
			"Y.`@.Y'D@J7A!\"YO!!!!!!!!!!!!!!!!!!!!!!!!'RI:D)K*````````````````"
			"````O<CY````````````Y^X;Y^\\=````````````[O,?X.H9````Q\\W\\M+[O!!!!"
			"!!!!!!!!!!!!!!!!!!!!!!!!>+7\\=L<5````MN4E=LL:````````GMH?G.0ODKCU"
			"````P/,T;,<:````````````P_0U:\\<;W^,/GN4O=\\,.FNHX!!!!!!!!!!!!!!!!"
			"!!!!!!!!<I;1:8O&QL__2:+TA:3>````````1)[Q,XWA````````+8_F99;8````"
			"````L=H6)8WG89+4TMP*3*+T.7O$4ZG[!!!!!!!!!!!!!!!!!!!!1U.$BI;'I;+C"
			"````RM8%````SML+L+SM````````L[_PXN\\?Z?$?X^\\?W>H:V^@8W>H:ZO(?X^\\?"
			"U.$1N<+RI[+CX>P;!!!!!!!!!!!!!!!!,S]P.45V!Q-$!!!!!!!!!!!!!!!!!!!!"
			"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
			"";

class DalekInstance {

public:
	int m_x;
	int m_y;
	Icon *m_icon;
	unsigned long m_t;
	DalekInstance(int x, int y, unsigned long t, Icon *icon) {
		m_x = x;
		m_y = y;
		m_t = t + micros();
		m_icon = icon;
		draw();
	}
	void draw() {
		m_icon->draw(m_x, m_y);
//		Hardware.drawIcon(14,m_x, m_y, &header_data[0]);
	}
	void erase() {
		Graphics.fillCircle(m_x + 7, m_y + 7, 10, BLACK);
		Graphics.setCursor(0, 0);
	}
	unsigned long getVanishTime() {
		return m_t;
	}
};

class Dalek: public App {
private:
	uint16_t m_cx;
	uint16_t m_cy;
	uint16_t m_height;
	uint16_t m_width;
	int circleSize;
	DalekInstance *daleks[DALEK_COUNT];
	int currentColour;
	int lastx;
	Icon m_smallIcon = Icon(14,&small_dalek_bitmap[0]);

public:
	Dalek();
	virtual unsigned long getUpdateInterval() {
		return 100000UL;
	};
	virtual void setup();
	virtual void init();
	virtual void display();
	virtual const char* getName() {
		return PSTR("Dalek");
	};

	virtual ~Dalek();
};

#endif /* MENU_H_ */
